package com.rongc.client.freight.business.waybill.view.adapter;

import android.content.Context;
import android.view.View;

import com.bumptech.glide.Glide;
import com.rongc.client.core.utils.StringUtils;
import com.rongc.client.freight.ApiUrl;
import com.rongc.client.freight.R;
import com.rongc.client.freight.base.view.adapter.RecyclerBaseAdapter;
import com.rongc.client.freight.business.waybill.model.LogisticsBean;

import java.util.ArrayList;
import java.util.List;

import cn.bingoogolapple.photopicker.activity.BGAPhotoPickerPreviewActivity;

import static com.rongc.client.freight.business.waybill.view.activity.HuidanActivity.MAX_PHOTO_COUNT;

/**
 * Created by ccqx on 2017/7/22.
 */

public class RecyclerWaybillAdapter extends RecyclerBaseAdapter<LogisticsBean> {

    public RecyclerWaybillAdapter(Context mContext, List<LogisticsBean> mDatas) {
        super(mContext, mDatas);
    }

    @Override
    protected void onBind(final BaseRecyclerViewHolder holder, int position, LogisticsBean data) {
        holder.setText(R.id.tv_date,data.getDate());
        holder.setText(R.id.tv_content,data.getLog());
        if(StringUtils.isNotEmpty(data.getImg())){
            holder.getImageView(R.id.iv_pic).setVisibility(View.VISIBLE);
//        holder.setImageResource(R.id.iv_pic,data.getImg());
            Glide.with(mContext.getApplicationContext())
                    .load(ApiUrl.getImgUrl(data.getImg()))
                    .placeholder(R.mipmap.schd_btn_upload)
                    .into(holder.getImageView(R.id.iv_pic));
        }else{
            holder.getImageView(R.id.iv_pic).setVisibility(View.GONE);

        }

        final ArrayList<String> pics = new ArrayList<>();
        pics.add(ApiUrl.getImgUrl(data.getImg()));
        holder.getImageView(R.id.iv_pic).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                mContext.startActivity(BGAPhotoPickerPreviewActivity.newIntent(mContext, MAX_PHOTO_COUNT, pics, pics, 0, false));
            }
        });


    }

    @Override
    protected int getLayoutId() {
        return R.layout.recycler_logistics_item;
    }
}
